package com.otherTest.other;


import org.junit.Test;

import java.util.HashMap;
import java.util.stream.Stream;

/**
 * @Description: php 用户表邀请码转换工具类
 * @author: conceit
 * @Date: 2018/10/16  16:08
 */
public class UserInvitationCodeUtil {

    private static  HashMap<Integer,Character> COMPATABLE;
    static {
        COMPATABLE=new HashMap<>();
        COMPATABLE.put(1,new Character('a'));
        COMPATABLE.put(2,new Character('b'));
        COMPATABLE.put(3,new Character('c'));
        COMPATABLE.put(4,new Character('d'));
        COMPATABLE.put(5,new Character('e'));
        COMPATABLE.put(6,new Character('f'));
        COMPATABLE.put(7,new Character('g'));
        COMPATABLE.put(8,new Character('h'));
        COMPATABLE.put(9,new Character('i'));
        COMPATABLE.put(0,new Character('j'));
    }


    public static String userInvitationCodeConvert(Integer invitationCode){
        if(invitationCode.compareTo(0)<=0){
            return new String("--");
        }
        StringBuffer sb=new StringBuffer();
        char[] strArray = String.valueOf(invitationCode).toCharArray();

        for (char i : strArray) {
            System.out.println(i);


            if(COMPATABLE.containsKey(new Integer(i))){
                sb.append(COMPATABLE.get(new Integer(i)));
            }

        }
        System.out.println(sb);
        return sb.toString();
    }

    @Test
    public void dotest(){
        userInvitationCodeConvert(1001);
    }

    @Test
    public void dotest2(){
        char i=1;
        if(COMPATABLE.containsKey(new Integer(i))){
            System.out.println("-->"+COMPATABLE.containsKey(new Integer(i)));
        }else{
            System.out.println("i not have-->");
        }

    }

    @Test
    public void dotest3(){
        char i=1;
        System.out.println("-->"+COMPATABLE.get(new Integer(i)));
    }


    @Test
    public void dotest4(){


        StringBuffer sb=new StringBuffer();
        char[] strArray = String.valueOf("1001").toCharArray();


        for (char i : strArray) {
            System.out.println(i);
            System.out.println(Integer.valueOf(String.valueOf(i)));

            if(COMPATABLE.containsKey(Integer.valueOf(String.valueOf(i)))){
                sb.append(COMPATABLE.get(Integer.valueOf(String.valueOf(i))));
            }

        }
        System.out.println(sb);
    }
}
